package com.zy.explore.web.security;

import lombok.Getter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import java.util.Collections;

/**
 * @author Administrator
 */
@Getter
public class ResolvedAuthenticationToken extends AbstractAuthenticationToken {

    private final String id;
    private final String type;
    private final String clientId;

    public ResolvedAuthenticationToken(String id, String type, String clientId) {
        super(Collections.singleton(new SimpleGrantedAuthority("ROLE_" + type)));
        this.id = id;
        this.type = type;
        this.clientId = clientId;
        setDetails(id);
        setAuthenticated(true);
    }

    public ResolvedAuthenticationToken() {
        super(null);
        this.id = null;
        this.type = null;
        this.clientId = null;
        setAuthenticated(false);
    }

    @Override
    public Object getCredentials() {
        return "[NO-PASS]";
    }

    @Override
    public String getPrincipal() {
        return id;
    }
}
